var db=wx.cloud.database()
// pages/order/index.js
Page({

  data: {
   tabs: [
      {
        id: 0,
        value: "全部订单",
        isActive: true
      }, {
        id: 1,
        value: "待付款",
        isActive: false
      }, {
        id: 2,
        value: "待发货",
        isActive: false
      }, {
        id: 3,
        value: "退款/退货",
        isActive: false
      }
    ]
  },
  onShow(options) {
    this.getorderList()
  } ,
    // 根据标题索引来激活选中 标题数组
    changeTitleByIndex(index) {
      // 2 修改源数组
      let { tabs } = this.data;
      tabs.forEach((v, i) => i === index ? v.isActive = true : v.isActive = false);
      // 3 赋值到data中
      this.setData({
        tabs
      })
    },
  tabsItemChange(e) {
    // 1 获取被点击的标题索引
    const { index } = e.detail;
    this.changeTitleByIndex(index);
  },
  async getorderList() {
    let that=this
    let openid=await wx.getStorage({
      key: 'openid',
    })
    openid=openid.data
    db.collection('orderList').where({
      _openid:openid
    })
    .get()
    .then(res=>{
      console.log(res);
      that.setData({
        orderList:res.data
      })
    })
  }
})